package InterfaceRational;

public class Rational {
	int numerator;
	int denominator;
	Rational(){
	}
	Rational(int a,int b){
		if(a==0){
			numerator=0;
			denominator=1;
		}
		else{
			setNumeratorAndDenominator(a,b);
		}
	}
	void setNumeratorAndDenominator(int a,int b){
		int c=f(Math.abs(a),Math.abs(b));
		numerator=a/c;
		denominator=b/c;
		if(numerator<0&&denominator<0){
			numerator=-numerator;
			denominator=-denominator;
		}
	}
	int getNumerator(){
		return numerator;
	}
	int getDenominator(){
		return denominator;
	}
	int f(int a,int b){
		if(a<b){
			int c=a;
			a=b;
			b=c;
		}
		int r=a%b;
		while(r!=0){
			a=b;
			b=r;
			r=a%b;
		}
		return b;
	}
}
